<template>
  <transition
    @enter="enter"
    @leave="leave">
    <div class="mini-player" v-show="this.isShowMiniPlayer">
    <div class="player-warpper">
      <div class="player-left" @click="showNormalPlayer">
        <img  ref="cd" :src="currentSong.picUrl" alt="">
        <div class="player-title">
          <h3>{{currentSong.name}}</h3>
          <p>{{currentSong.singer}}</p>
        </div>
      </div>
      <div class="player-right">
        <div class="play" @click="play" ref="play"></div>
        <div class="list" @click.stop="showList"></div>
      </div>
    </div>
  </div>
  </transition>
</template>

<script>
import {mapActions,mapGetters} from 'vuex';
import Velocity from 'velocity-animate'
import 'velocity-animate/velocity.ui'
export default {
  name:"MiniPlayer",
  methods:{
    //显示播放列表
    showList(){
      // this.$emit("showList")
      this.setListPlayer(true)
    },
    ...mapActions([
      'setFullScreen',
      'setMiniPlayer',
      'setIsPlaying',
      'setListPlayer'
    ]),
    //显示播放界面
    showNormalPlayer(){
      //显示播放界面
      this.setFullScreen(true);
      //关闭mini播放界面
      this.setMiniPlayer(false)
    },
    //播放?暂停按钮
    play(){
      this.setIsPlaying(!this.isPlaying)
    },
    //mini播放器入场动画
    enter(el,done){
      Velocity(el, 'transition.flipXIn', { duration: 650 },function(){
        done()
      })
    }, 
    //mini播放器离场动画
    leave(el,done){
      Velocity(el, 'transition.flipXOut', { duration: 650 },function(){
        done()
      })
    },
  },
  computed:{
    ...mapGetters(['isShowMiniPlayer','isPlaying','currentSong']),
  },
  watch:{
    //play - 修改播放?暂停图片
    //cd - 图片旋转动画
    isPlaying(newValue,oldValue){
      if(!newValue){
        this.$refs.play.classList.remove('active');
        this.$refs.cd.classList.remove('active')
      }else{
        this.$refs.play.classList.add('active');
        this.$refs.cd.classList.add('active') 
      }
    }
  }
}
</script>

<style lang="scss" scoped>
@import"../../assets/css/mixin";
@import"../../assets/css/variable";
.mini-player{
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 150px;
  .player-warpper{
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    @include bg_color();
    .player-left{
      display: flex;
      margin-left: 30px;
      img{
        width: 100px;
        height: 100px;
        border-radius: 50%;
        margin-right: 20px;
        animation: sport 3s linear infinite;
        animation-play-state: paused;//动画暂停
        &.active{
          animation-play-state: running;//动画开始
        }
      }
      .player-title{
        display: flex;
        flex-direction: column;
        justify-content: center;
        h3{
          @include font_color();
          @include font_size($font_medium);
        }
        p{
          @include font_color();
          @include font_size($font_medium_s);
        }
      }
    }
    .player-right{
      display: flex;
      align-items: center; 
      .play{
        width: 84px;
        height: 84px;
        @include bg_img('../../assets/images/play');
        &.active{
        @include bg_img('../../assets/images/pause');
        }
      }
      .list{
        width: 120px;
        height: 120px;
        @include bg_img('../../assets/images/list');
      }
    }
  }
}
//图片旋转动画
  @keyframes sport {
    from{
      transform: rotate(0deg);
    }to{
      transform: rotate(360deg);
    }
  }
</style>